﻿@model ItemModel<Post>
@{
    var blog = Model.Blog;
    var post = Model.Item;

    this.SetViewPropertiesFrom(post);

    var tags = post.Tags.OrderBy(t => t.Title);
    var disqus = blog.Property().Disqus as string;
    var showComments = post.AllowComments && !string.IsNullOrWhiteSpace(disqus);
}
<article role="article">
    <header>
        <time datetime="@post.PublishedAt.ShortFormat()">@post.PublishedAt.LongFormat()</time>
        <h1>@post.Title</h1>
    </header>
    <div>
        @Html.Raw(Renderer.RenderFull(post))
    </div>
    <footer role="contentinfo">
        This post was published on <time datetime="@post.PublishedAt.ShortFormat()" pubdate="pubdate">@post.PublishedAt.LongFormat()</time>
        by @(post.Author ?? blog.Author)
        @RenderTags(tags).
        @if (showComments) {
            <text> You can skip to the end and</text> <a href="#dsq-form-area">leave your comment</a><text>.</text>
        }
    </footer>
    @if (showComments) {
        @Html.Partial("_CommentList", disqus)
    }
</article>
@section StyleSheets {
    @{ var styleSheets = Model.Item.Property().StyleSheets as IEnumerable<string>; }
    @styleSheets.RenderEach(@<link rel="stylesheet" href="@Url.JavaScript(item)"/>)
}
@section JavaScripts {
    @{ var javaScripts = Model.Item.Property().JavaScripts as IEnumerable<string>; }
    @javaScripts.RenderEach(@<script src="@Url.JavaScript(item)"></script>)
}
@helper RenderTags(IEnumerable<Tag> tags){

    var tagList = tags.ToList();

    if (tagList.Any()) {
        <text> under </text>
    }

    for (int i = 0; i < tagList.Count; i++)
    {
        if (i > 0) {
            <text>, </text>
        }

        var tag = tagList[i];

        @Html.ActionLink(tag.Title, "tagged", "posts", new { page = 1, slug = tag.Slug.ToLowerInvariant() }, new { rel = "tag" })
    }
}